package sisdroid.client;

import java.util.*;

import sisdroid.client.model.Location;

import android.app.Activity;
import android.bluetooth.*;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.location.GpsStatus.Listener;
import android.os.Bundle;
import android.util.Log;
import static android.bluetooth.BluetoothAdapter.STATE_ON;
import static android.bluetooth.BluetoothDevice.*;

public class GpsDiscoverer implements NetDiscoverer
{

	Context 									caller;
	BluetoothAdapter 							bt;
	LocationManager								manager;
	LocationProvider							provider;
	Location									currentLocation;
	public GpsDiscoverer( Context caller )
	{
		currentLocation = null;
		this.caller		= caller;
		manager			= (LocationManager) caller.getSystemService( Context.LOCATION_SERVICE );
		provider		= manager.getProvider("gps");
		
		manager.requestLocationUpdates("gps", 60000, 0, new LocationListener(){
			@Override
			public void onStatusChanged(String provider, int status,
					Bundle extras)
			{
				
			}

			@Override
			public void onLocationChanged(android.location.Location location)
			{
				currentLocation = new Location("gps", location.getLatitude() + "/" + location.getLongitude());
		
			}

			@Override
			public void onProviderDisabled(String provider)
			{
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onProviderEnabled(String provider)
			{
					// TODO Auto-generated method stub
		
			}		
		} );
	}

	
	@Override
	public Set<sisdroid.client.model.Location> getNetIDS()
	{
		HashSet<sisdroid.client.model.Location> result = new HashSet<Location>();
		
		// TODO: find way to validate that currentLocation is valid and current.
		if ( currentLocation != null ) result.add( currentLocation );
		
		return result;
	}

}
